package com.group.transaction.service.dept.impl;

import com.alibaba.fastjson.JSONObject;
import com.group.transaction.domain.Dept;
import com.group.transaction.mapper.DeptMapper;
import com.group.transaction.service.dept.DeptService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
@Service
public class DeptServiceImpl implements DeptService {
    @Resource
    private DeptMapper deptMapper;

    /**
     * 添加部门
     * @param dept
     * @return
     */
    @Override
    @Transactional
    public JSONObject addDept(Dept dept){
        return new JSONObject().fluentPut("result",deptMapper.insert(dept));
    }
    /**
     * 编辑部门
     * @param dept
     * @return
     */
    @Override
    @Transactional
    public JSONObject compileDept(Dept dept){
        return new JSONObject().fluentPut("result",deptMapper.updateByPrimaryKey(dept));
    }
    /**
     * 删除部门
     * @param dept
     * @return
     */
    @Override
    @Transactional
    public JSONObject deleteDept(Dept dept){
        return new JSONObject().fluentPut("result",deptMapper.delete(dept));
    }
    /**
     * 查询部门
     * @param dept
     * @return
     */
    @Override
    public JSONObject queryDeptData(Dept dept){
        try {
            List<Dept> deptList = deptMapper.queryDeptData(dept);
            Integer total = deptMapper.queryDeptDataTotal(dept);
            return new JSONObject().fluentPut("result",deptList).fluentPut("total",total);
        } catch (Exception e) {
            return new JSONObject().fluentPut("result", null);
        }
    }
}
